       var serviceUrl;
       
	   var labLastStamp;
	   var taDebug;

       var request=HTTP.newRequest();
       
       
       function setServiceUrl(url){
          serviceUrl=url;
       }
       
	   function callbackData(jsontext){
	   }
	   function errorHandler(msg){
	      alert(msg);
	   }
       
       function postAndDataAction(url, values, callback, rootData, errorHandler) {
         var request = HTTP.newRequest();
         request.onreadystatechange = function() {
           if (request.readyState == 4) {
              if (request.status == 200) {
                  var jsontext=HTTP._getResponse(request);
    	          if(taDebug!=null)
        		      taDebug.value=jsontext;
                  var newdata = eval ('('+jsontext+')');
                  if(rootData!=null){
                    mergeData(rootData, newdata);	   
                  }
                  callback();
              }
              else {
                  if (errorHandler) {
                    var tmp=url;
                    for (k in values){
                       tmp+="\n\t"+k+"\t"+values[k];
                    }
                    tmp+="\n"+request.status+ ":" +request.statusText;
                    errorHandler(tmp);
                  }
                  else callback(null);
              }
            }
         }

         request.open("POST", url);
         // This header tells the server how to interpret the body of the request
         request.setRequestHeader("Content-Type",
                             "application/x-www-form-urlencoded");
         // Encode the properties of the values object and send them as
         // the body of the request.
         request.send(HTTP.encodeFormData(values));
       };
       /**
       params: hash of extra params to be  paseed to the url
       callback: function to be caled once the request has completed
       rootData: where to store the info (can be null);
       */
       function refreshData(params, callback, rootData){
          var urlparams={
              'recentthan':rootData['mtime'],
              'action':'list',
              'out':'json'
              };
          if(params!=null){
              for (k in params){
                  urlparams[k]=params[k];
              }
          }
          postAndDataAction(serviceUrl, urlparams, callback, rootData, errorHandler);
       }
       
       function initData(){
          return {'stamps':new Array(),
                  'files':new Array(),
                  'mtime':0
                 };
       }
       
       function mergeData(rootData, newdata){
           if (newdata['mtime'] != null){
             rootData['mtime']=newdata['mtime'];
           }
           if (newdata['files'] != null){
             var newStamps=newdata['timestamps'];
             if(labLastStamp!=null)
                labLastStamp.innerHTML=newStamps[0];
             
             var aStamps=rootData['stamps'];
             var fileList=rootData['files'];
             
             lstamp=(aStamps.length)?aStamps[0]:null;
             for(i=0; i<newStamps.length; i++){
               if(newStamps[i]==lstamp){
                  newStamps.length=i;
                  break;
               }
             }
             for(i=newStamps.length-1; i>=0; i--){
               aStamps.unshift(newStamps[i]);
             }
             for(l in newdata['files']){
             	for (s in newdata['files'][l]['stamped']){
             	   if(fileList[l]==null){
             	      fileList[l]=new Array();
             	   }
             	   fileList[l][s]=newdata['files'][l]['stamped'][s];
             	}
             }
           }
       }
       
      function getFile(rootData, label, i, tol){
         var aStamps=rootData['stamps'];
         var fileList=rootData['files'];
         if(tol==null){
           tol=0;
         }
         if(fileList[label]==null){
           return null;
         }
         if(i==null){
            i=0;
         }
         if(i==0 || i >=1){//number
         	for(j=i; j<=i+tol; j++){
         	  s=aStamps[j];
         	  if(fileList[label][s]!=null){
         	    return fileList[label][s];
         	  }
            }
            return null;
         }
         for (s in fileList[label]){
            
         }
         return null;
      }
       